#ifndef _DDI_PED_
#define _DDI_PED_

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct _TPKeyBoardInfo
{
    int xStart;
    int xEnd;
    int yStart;
    int yEnd;
    int keyBoardHeight;
    int keyBoardWidth;
    int xGap;
    int yGap;
    int keyBoardRowNum;
    int keyBoardColNum;
} TPKeyBoardInfo;

typedef struct
{

    uint8_t m_keygroupidx;      /*密钥组号*/
    uint8_t m_srckeytype;       /*发散该密钥的源密钥的密钥类型，不得低于dstkeytype所在的密钥级别*/
    uint8_t m_srckeyindex;      /*源密钥索引号*/
    uint8_t m_dstkeytype;       /*目的密钥类*/
    uint8_t m_dstkeyindex;      /*目的密钥索引号*/
    uint32_t m_dstkeylen;       /*目的密钥数据长度*/
    uint8_t m_dstkeyvalue[256]; /*目的密钥内容*/

} ST_PED_KEY_INFO;

typedef struct
{

    uint8_t m_checkMode;      /*校验模式*/
    uint32_t m_checkdatalen;  /*校验数据长度*/
    uint8_t m_checkdata[256]; /*校验数据缓冲区*/

} ST_PED_KCV_INFO;

typedef struct
{

    uint32_t m_pinblockdatalen;  /*pinblock数据长度*/
    uint8_t m_pinblockdata[512]; /*pinblock数据缓冲区*/
    uint8_t m_ksnlen;            /*ksn len*/
    uint8_t m_ksn[32];           /*ksn数据缓冲区(HEX格式KSN)*/

} ST_PED_PINBLOCKDATA;

typedef struct
{

    uint32_t m_macdatalen;       /*macblock数据长度*/
    uint8_t m_macblockdata[256]; /*macblock数据缓冲区*/
    uint8_t m_ksnlen;            /*ksn len*/
    uint8_t m_ksn[32];           /*ksn数据缓冲区(HEX格式KSN)*/
} ST_PED_MACDATA;

typedef struct
{

    uint32_t m_accountdatalen;       /*macblock数据长度*/
    uint8_t m_accountblockdata[256]; /*macblock数据缓冲区*/
    uint8_t m_ksnlen;                /*ksn len*/
    uint8_t m_ksn[32];               /*ksn数据缓冲区(HEX格式KSN)*/
} ST_PED_ACCOUNTDATA;

/** 获取明文硬件序列号
 * @param[out] result 返回结果。
 * @param[in,out] result_len 结果长度。
 * @return 状态码。
 */
int ddi_ped_get_plain_serial_no(uint8_t *result, uint16_t *result_len);

/** 获取密文硬件序列号
 * @param[in] encrypt_mode 加密模式 des/3des :0  SM4 :1
 * @param[in] plain_serial_no 硬件序列号。
 * @param[in] plain_serial_no_len 序列号长度。
 * @param[in] encrypt_factor 加密随机因子。
 * @param[in] data_len 加密随机因子的长度。
 * @param[out] result 返回结果。
 * @param[in,out] result_len 结果长度。
 * @return 状态码。
 */
int ddi_ped_get_encrypt_serial_no(uint16_t encrypt_mode, uint8_t *plain_serial_no, uint16_t serial_no_len, uint8_t *encrypt_factor, uint16_t encrypt_factor_len, uint8_t *result, uint16_t *result_len);

int ddi_ped_pci_cardhorderpininput(int32_t pinlenmin, int32_t pinlenmax, int32_t timeout, int32_t bypassflag);

int ddi_ped_pci_getpinblock(int32_t command, uint8_t *keydata, int32_t keydatalen, uint8_t *pinblock, int32_t pinblockbuflen);

int ddi_ped_pci_getmac(int32_t command, uint8_t *keydata, int32_t keydatalen, uint8_t *macblock, int32_t macblockbuflen);
int ddi_ped_pci_getencryptedtrackdata(int32_t command, uint8_t *keydata, int32_t keydatalen, uint8_t *encryptdtrackdata, int32_t encryptedmagdatabuflen);

int ddi_ped_pci_getkeystatus(uint8_t groupindex, uint8_t keytype, uint8_t keyindex, uint8_t *tradedata, int32_t tradedatalen);

int ddi_ped_pci_getcardholderinputpin(int32_t command, uint8_t *pindata, int32_t pindatabuflen);

int ddi_ped_pci_generatetransdukptkey(uint8_t groupindex, uint8_t keyindex, uint8_t dukpttype);

int ddi_ped_pci_readtlsfile(uint8_t *tlsfilename, uint8_t *tlsfiledata, int32_t tlsfiledatalen);

int ddi_ped_pci_getrandomkeypadlayout(uint8_t *keypaddom, uint8_t keypaddombuflen);

int ddi_ped_pci_settpkeyboardinfo(TPKeyBoardInfo *sptpkeyboardinfo);

int ddi_ped_writekey(ST_PED_KEY_INFO *keyinfoin, ST_PED_KCV_INFO *kcvinfoin);

int ddi_ped_writeTIK(uint8_t ksnlenin, uint8_t *ksnin, ST_PED_KEY_INFO *keyinfoin, ST_PED_KCV_INFO *kcvinfoin);

int ddi_ped_entercardholderpininputmode(uint8_t keygroupindex, uint8_t pinkeytype, uint8_t pinkeyindex, uint8_t mode, uint8_t bypassenable,
                                        uint8_t minpinlen, uint8_t maxpinlen, uint32_t timeoutms);

int ddi_ped_exitcardholderpininputmode();

int ddi_ped_getpinblock(uint8_t keygroupidx, uint8_t pinkeytype, uint8_t pinkeyindex, uint8_t mode, uint8_t derivekeytype, uint32_t datainlen,
                        uint8_t *datain, ST_PED_PINBLOCKDATA *pinblockdataout);

int ddi_ped_getmac(uint8_t keygroupidx, uint8_t mackeytype, uint8_t mackeyindex, uint8_t mode, uint8_t derivekeytype, uint8_t derivekeyusage,
                   uint32_t datainlen, uint8_t *datain, ST_PED_MACDATA *macdataout);

int ddi_ped_encryptaccountdata(uint8_t keygroupidx, uint8_t tdkkeytype, uint8_t tdkkeyindex, uint8_t mode, uint8_t derivekeytype,
                               uint8_t derivekeyusage, uint32_t datainlen, uint8_t *datain, ST_PED_ACCOUNTDATA *accountdataout);

int ddi_ped_regentdesdukptkey(uint8_t keygroupidx, uint8_t tdesdukptkeyindex, uint8_t mode, uint32_t datainlen, uint8_t *datain);

int ddi_ped_regenaesdukptkey(uint8_t keygroupidx, uint8_t aesdukptkeyindex, uint8_t mode, uint32_t datainlen, uint8_t *datain);

int ddi_ped_getkeykcv(uint8_t keygroupidx, uint8_t keytype, uint8_t keyindex, ST_PED_KCV_INFO *kcvinfoout);

int ddi_ped_getpinkeyvalue(uint8_t *pindata, int32_t pindatabuflen);

#ifdef __cplusplus
}
#endif

#endif